package com.yf.learning.designpattern.singleton;

/**
 * reffer to: https://blog.csdn.net/jason0539/article/details/23297037/
 */
public class Singleton {

    private Singleton() {
    }

    private static Singleton singleton = null;

    //懒汉式单例类.在第一次调用的时候实例化自己
    //1、在getInstance方法上加同步
    public static Singleton getInstance() {
        if (singleton == null) {
            singleton = new Singleton();
        }
        return singleton;
    }



    //2、双重检查锁定
    /**
    public static Singleton getInstance() {
        if (singleton == null) {
            synchronized (Singleton.class) {
                if (singleton == null) {
                    singleton = new Singleton();
                }
            }
        }
        return singleton;
    }
     */

    /**
     * TODO: 好多别的单例模式的写法
     */


}


